<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> 
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>新增角色</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script src="${ctx}/rs/js/jquery.validate.min.js"></script>
<script src="${ctx}/rs/js/jquery.form.js" type="text/javascript"></script>
<style type="text/css">
	#quotationSetting tr th{text-align: center;vertical-align: middle;border: 1px #E3E3E3 solid !important;}
</style>
</head>
<body>
<form id="form2" class="form-horizontal">
	<table id="quotationSetting" class="table table-bordered">
		<thead>
			<tr>
				<th rowspan="2" style="width: 100px;">时段名称</th>
				<th colspan="${fn:length(durationList)}">广告报价（元/次）</th>
			</tr>
			<tr>
				<c:forEach items="${durationList}" var="item">
					<th>${item.value}秒</th>
				</c:forEach>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${timeLevelList}" var="item" varStatus="statusi">
				<tr>
					<td>${item.value}</td>
					<c:forEach items="${durationList}" var="item2" varStatus="statusj">
						<td class="form-group"><input type="text" name="${item.id}_${item2.value}" class="form-control" n="true" required="true" maxlength="6" min="1"/></td>
					</c:forEach>
				</tr>
			</c:forEach>
		</tbody>
	</table>
	<hr/>
	<div class="row text-center">
		<a class="btn btn-primary mr15" onclick="valiSubmit2();">保存</a>
		<a class="btn btn-danger" onclick="reset2();">重置</a>
	</div>
</form>


<script type="text/javascript" src="${ctx}/rs/js/bootstrapQ.min.js"></script>
<script src="${ctx}/rs/js/messages_zh.min.js"></script>
<script type="text/javascript">
	$.validator.addMethod("n", function(value, element) {
	   var aint=parseInt(value);	
	    return aint>0&& (aint+"")==value;   
	  }, "请输入正整数");  
	
	$.validator.addMethod("selectRequired", function(value, element) {
    	value = $(element).val();
    	var flag = (value!=null&&value!=undefined&&value>0);
    	return true&&flag;
    }, "必须填写");

    //初始化验证 start
    var form2 = $('#form2');
    var validator2 = form2.validate({
		rules: {
			
		  },
		  highlight: function(element) {
			  $(element).closest('.form-group').removeClass('success').addClass('error');
		  },
		  success: function(element) {
			  element.text('OK!').addClass('valid')
		      .closest('.form-group').removeClass('error').addClass('success');
		  }
    });
    /** end */

	function valiSubmit2() {
		if (form2.valid()) {
			var data = $("#form2").serialize(); //获取表单多个控件的数据
			console.log(data);
			$("#hid_quotation").val(data);
			//触发隐藏确认的按钮，引用回调方法关闭窗口并刷新列表
			$("button.bsok").click();
		}
	}
    
    function reset2(){
    	validator2.resetForm();
    	form2.find(".form-group.success").removeClass("success");
    	form2.find(".form-group.error").removeClass("error");
    	form2.find(":input.valid").removeClass("valid");
    }
</script>	
</body>
</html>